package 力扣日常刷题.木22二月.第12天218;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 帅小伙
 * @date 2022/2/18
 * @description
 */
public class Demo89Z字形变化 {


    public String convert(String s, int numRows) {
        if (numRows < 2) return s;
        List<StringBuilder> rows = new ArrayList<StringBuilder>();
        for (int i = 0; i < numRows; i++) rows.add(new StringBuilder());
        int i = 0, flag = -1;
        for (char c : s.toCharArray()) {
            rows.get(i).append(c);
            if (i == 0 || i == numRows - 1) flag = -flag;
            i+= flag;
        }
        StringBuilder ans = new StringBuilder();
        for (StringBuilder row : rows)  ans.append(row);
        return ans.toString();
    }

}
